import { computed, isRef } from 'vue';



export function useUploadPercentage(chunkData, container) {
    return computed(() => {
        if (!container.file || isRef(chunkData) ? !chunkData.value.length : !chunkData.length) return 0;

        // 获取所有chunk的进度总和，结果自身已经乘以100，所以结果是文件大小的100倍，也就是直接可以用于百分比10 => 10%
        const loaded = (isRef(chunkData) ? chunkData.value : chunkData)
            .map((item) => {
                console.log(item, item.percentage);
                return item.chunk.size * item.percentage;
            })
            .reduce((acc, cur) => acc + cur);

        return parseFloat((loaded / container.file.size).toFixed(2));
    });
}